package com.sfac.springBoot.module.test.controller;

import com.sfac.springBoot.module.common.vo.Result;
import com.sfac.springBoot.module.common.vo.Search;
import com.sfac.springBoot.module.test.pojo.Student;
import com.sfac.springBoot.module.test.service.StudentService;
import javafx.beans.binding.ObjectExpression;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * personal demo
 **/
@RestController
@RequestMapping("/api")
public class StudentController {
    @Autowired
    private StudentService studentService;

    @PostMapping(value = "/student",consumes = MediaType.APPLICATION_JSON_VALUE)
    public Result<Student> insertStudent(@RequestBody Student student){
        return studentService.insertStudent(student);
    }

    @PutMapping(value = "/student",consumes = MediaType.APPLICATION_JSON_VALUE)
    public Result<Student> updateStudent(@RequestBody Student student){
        return studentService.updateStudent(student);
    }

    @DeleteMapping(value = "/student/{id}")
    public Result<Object> deleteStudent(@PathVariable int id){
        return studentService.deleteStudentById(id);
    }

    @GetMapping(value = "/student/{id}")
    public Student getStuById(@PathVariable  int id) {
        return studentService.getStuById(id);
    }

    @PostMapping(value = "/students",consumes = MediaType.APPLICATION_JSON_VALUE)
    public Page<Student> getStuBySearch(@RequestBody Search search){
        return studentService.getStuBySearch(search);

    }


}
